<?php

namespace App\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use HasFactory;

    protected $dateFormat = 'U';
    protected $table = 'order';
    protected $fillable = ['id','order_no','product_item','status','users_id'
        ,'pay_price','address','pay_mode','delivery_type','order_type','remark',
        'make_time','time','date','products_id'];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function getProductItemAttribute($value)
    {
        return json_decode($value, true);
    }

    public function getAddressAttribute($value)
    {
        return json_decode($value, true);
    }

    public function getMakeTimeAttribute($value)
    {
        return   empty($value) ? $value :  date('Y-m-d H:s',$value);

    }

    
}
